using UnityEngine;
using System.Collections;

public class BrowseEditEntry : MonoBehaviour {
	
	public HelperFunctions.ObjectType entryType;
	public string entryFile;
	public string entryName;
	public string entryDescription;
	public UICheckbox toggler;
	public UILabel nameLabel;
	public GameObject infoButton;
	
	public GameObject callBackTarget;
	public string infoCallBack = "infoButtonHit";
	public string toggledCallback = "entryToggled";
	
	public bool infoDoesntEdit = false;

	// Use this for initialization
	void Start () {
		toggler.functionName = "toggled";
		toggler.eventReceiver = gameObject;
		
		UIButtonMessage message = infoButton.AddComponent<UIButtonMessage>();
		message.target = gameObject;
		message.functionName = "infoHit";
	}
	
	// Update is called once per frame
	void Update () {
		
	}
	
	public void Setup(string name, HelperFunctions.ObjectType type, bool disableInfoEdit = false)
	{
		entryFile = name;
		entryName = HelperFunctions.getRealName(name, type);
		entryType = type;
		nameLabel.text = name;
		if(nameLabel.text.EndsWith("@")||nameLabel.text.EndsWith("$")||nameLabel.text.EndsWith("^"))
			nameLabel.text = nameLabel.text.Remove(nameLabel.text.Length-1);
		infoDoesntEdit = disableInfoEdit;
	}
	
	public void toggled(bool selected)
	{
		if(callBackTarget != null)
			callBackTarget.SendMessage(toggledCallback,this,SendMessageOptions.DontRequireReceiver);
	}
	
	public void infoHit()
	{		
		if(callBackTarget != null)
			callBackTarget.SendMessage(infoCallBack,this,SendMessageOptions.DontRequireReceiver);
	}
	
	public void setupClick()
	{
		toggler.isChecked = true;
	}
}
